class Solution:
    def longestPalindrome(self, s: str) -> str:
    """
        给你一个字符串 s，找到 s 中最长的回文子串。
        示例 1：
        输入：s = "babad"
        输出："bab"
        解释："aba" 同样是符合题意的答案。
    """
        self.maxs = s[0]
        for i in range(len(s)-1):
            if i>0 and s[i-1] == s[i+1]:
                l = i-1
                r = i+1
                self.compare(l, r, s)
            
            if s[i] == s[i+1]:
                l = i
                r = i+1
                self.compare(l, r, s)
                
        return self.maxs
               
    def compare(self, l, r, s):
        while l>0 and r<len(s)-1 and s[l-1]==s[r+1]:
            l-=1
            r+=1
        if r+1-l > len(self.maxs):
            self.maxs = s[l:r+1]